﻿<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        '
        '   default.aspx
        '
        '   part of WHMCSdotnet (http://whmcsdotnet.wordpress.com)
        '
        '   Copyright (C) 2009-2011 Mark Castle <markcastle@gmail.com>
        '   All rights reserved. 
        '   Copyright (C) 2009-2011 Secura Hosting Ltd <code@securahosting.com>.
        '   All rights reserved.
        ' 
        '   Redistribution and use in source and binary forms, with or without modification,
        '   are permitted provided that the following conditions are met:
        ' 
        '   - Redistributions of source code must  retain  the  above copyright notice, this
        '     list of conditions and the following disclaimer.
        ' 
        '   - Redistributions in binary form  must  reproduce the  above  copyright  notice,
        '     this list of conditions  and  the  following  disclaimer in  the documentation
        '     and/or other materials provided with the distribution.
        ' 
        '   - Neither  the  name  of  Secura Hosting Ltd, Mark Castle  nor the names of  its
        '     contributors may be used to endorse or  promote  products  derived  from  this
        '     software without specific prior written permission.
        ' 
        '   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
        '   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT  NOT  LIMITED TO, THE IMPLIED
        '   WARRANTIES  OF  MERCHANTABILITY   AND  FITNESS  FOR  A  PARTICULAR  PURPOSE  ARE
        '   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
        '   ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        '   (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT  OF  SUBSTITUTE  GOODS OR SERVICES;
        '   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  HOWEVER  CAUSED AND ON
        '   ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
        '   (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING  IN  ANY WAY OUT OF THE USE OF THIS
        '   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

        ' **** IMPORTANT ****
        ' Don't forget to add your IP to the Allowed IP's in WHMCS
        ' Setup --> Security --> API IP Access Restriction
        ' **** IMPORTANT ****
        
        ' Create an API sessings object, pass our WHMCS API credentials to it..
        Dim APISettings As New Secura.WHMCS.API.Settings
        APISettings.Url = System.Configuration.ConfigurationManager.AppSettings("WHMCS.APIUrl").ToString()
        APISettings.Username = System.Configuration.ConfigurationManager.AppSettings("WHMCS.Username").ToString()
        APISettings.Password = System.Configuration.ConfigurationManager.AppSettings("WHMCS.Password").ToString()
        
        ' **** Uncomment this to get all invoices for a specific user
        'Dim NewInvoices As New Secura.WHMCS.GetInvoices()
        'NewInvoices.UserID = 1
        'Dim GetActivityLog As New Secura.WHMCS.GetActivityLog()
        'Results.Text = Secura.WHMCS.API.PostRequest(GetActivityLog, "", "")
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(GetActivityLog)
        
        ' **** Uncomment this to test the WHOIS function
        'Dim WHMCSAPI As New Secura.WHMCS.DomainWHOIS()
        'WHMCSAPI.Domain = "facebook.com"
        'Results.Text = Server.HtmlEncode(Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", ""))
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
        ' **** Uncomment this to get an invoice
        'Dim WHMCSAPI As New Secura.WHMCS.GetInvoice()
        'WHMCSAPI.InvoiceId = 1
        'Results.Text = Server.HtmlEncode(Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", ""))
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
        ' **** Uncomment this to test the GetProducts API function
        'Dim WHMCSAPI As New Secura.WHMCS.GetProducts()
        'WHMCSAPI.Module = "onapp"
        'Dim Response As Secura.WHMCS.Response = Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", "")
        'Results.Text = Server.HtmlEncode(Response.Xml.ToString())
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
        ' **** Uncomment this to test the GetClients API function       
        'Dim WHMCSAPI As New Secura.WHMCS.GetClients()
        'Dim Response As Secura.WHMCS.Response = Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", "")
        'Results.Text = Server.HtmlEncode(Response.Xml.ToString())
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
   
        ' **** Uncomment this to test the GetClientsDetails API function
        Dim WHMCSAPI As New Secura.WHMCS.GetClientsDetails()
        WHMCSAPI.ClientId = 1
        Dim Response As Secura.WHMCS.Response = Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", "")
        Results.Text = Server.HtmlEncode(Response.Xml.ToString())
        WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
        ' **** Demonstrating how to use the response object...
        If Not (IsNothing(Response)) Then
            Results.Text &= "<hr/>" & "ResponseXml: <br/>" & vbCrLf & Server.HtmlEncode(Response.Xml)
            Results.Text &= "<hr/>" & vbCrLf
            Results.Text &= "Action: " & Response.Action.ToString() & vbCrLf
            Results.Text &= "Success: " & Response.Success.ToString() & vbCrLf
            Results.Text &= "TotalResults: " & Response.TotalResults.ToString() & vbCrLf
            Results.Text &= "Errors: " & Response.Errors.ToString() & vbCrLf
            Results.Text &= "Message: " & Response.Message.ToString() & vbCrLf
            
            ' Demonstrating how to iterate through the the response.clients collection
            If Not (Response.Clients Is Nothing) Then
                Results.Text &= "Clients.Count: " & Response.Clients.Count.ToString() & vbCrLf
                For Each Client As Secura.WHMCS.Data.Client In Response.Clients
                    Results.Text &= "-------Client--------<br/>" & vbCrLf
                    Results.Text &= "Id: " & Client.Id.ToString() & vbCrLf
                    Results.Text &= "Firstname: " & Client.Firstname.ToString() & vbCrLf
                    Results.Text &= "Lastname: " & Client.Lastname.ToString() & vbCrLf
                    Results.Text &= "EMail: " & Client.EMail.ToString() & vbCrLf
                    Results.Text &= "CompanyName: " & Client.CompanyName.ToString() & vbCrLf
                    Results.Text &= "GroupID: " & Client.GroupID.ToString() & vbCrLf
                    Results.Text &= "DateCreated: " & Client.DateCreated.ToString() & vbCrLf
                    Results.Text &= "Status: " & Client.Status.ToString() & vbCrLf
                Next
            End If

            ' **** Response.ClientDetails 
            If Not (Response.ClientDetails Is Nothing) Then
                Results.Text &= "-------ClientDetails--------" & vbCrLf
                Results.Text &= "Id: " & Response.ClientDetails.Id.ToString() & vbCrLf
                Results.Text &= "UserId: " & Response.ClientDetails.UserId.ToString() & vbCrLf
                Results.Text &= "Firstname: " & Response.ClientDetails.FirstName.ToString() & vbCrLf
                Results.Text &= "Lastname: " & Response.ClientDetails.LastName.ToString() & vbCrLf
                Results.Text &= "EMail: " & Response.ClientDetails.Email.ToString() & vbCrLf
                Results.Text &= "CompanyName: " & Response.ClientDetails.CompanyName.ToString() & vbCrLf
                Results.Text &= "Address1: " & Response.ClientDetails.Address1.ToString() & vbCrLf
                Results.Text &= "Address2: " & Response.ClientDetails.Address2.ToString() & vbCrLf
                Results.Text &= "City: " & Response.ClientDetails.City.ToString() & vbCrLf
                Results.Text &= "State: " & Response.ClientDetails.State.ToString() & vbCrLf
                Results.Text &= "Postcode: " & Response.ClientDetails.Postcode.ToString() & vbCrLf
                Results.Text &= "Country: " & Response.ClientDetails.Country.ToString() & vbCrLf
                Results.Text &= "CountryName: " & Response.ClientDetails.CountryName.ToString() & vbCrLf
                Results.Text &= "PhoneNumber: " & Response.ClientDetails.PhoneNumber.ToString() & vbCrLf
                Results.Text &= "Notes: " & Response.ClientDetails.Notes.ToString() & vbCrLf
                Results.Text &= "Password: " & Response.ClientDetails.Password.ToString() & vbCrLf
                Results.Text &= "Currency: " & Response.ClientDetails.Currency.ToString() & vbCrLf
                Results.Text &= "SecurityQID: " & Response.ClientDetails.SecurityQID.ToString() & vbCrLf
                Results.Text &= "SecurityQans: " & Response.ClientDetails.SecurityQans.ToString() & vbCrLf
                Results.Text &= "GroupID: " & Response.ClientDetails.GroupId.ToString() & vbCrLf
                Results.Text &= "Status: " & Response.ClientDetails.Status.ToString() & vbCrLf
                Results.Text &= "Credit: " & Response.ClientDetails.Credit.ToString() & vbCrLf
                Results.Text &= "TaxExempt: " & Response.ClientDetails.TaxExempt.ToString() & vbCrLf
                Results.Text &= "LateFeeOveride: " & Response.ClientDetails.LateFeeOveride.ToString() & vbCrLf
                Results.Text &= "OverideDueNotices: " & Response.ClientDetails.OverideDueNotices.ToString() & vbCrLf
                Results.Text &= "Language: " & Response.ClientDetails.Language.ToString() & vbCrLf
                Results.Text &= "LastLogin: " & Response.ClientDetails.LastLogin.ToString() & vbCrLf
                Results.Text &= "BillingCid: " & Response.ClientDetails.BillingCid.ToString() & vbCrLf
                Results.Text &= "Currency_Code: " & Response.ClientDetails.Currency_Code.ToString() & vbCrLf
                Results.Text &= "CCType: " & Response.ClientDetails.CCType.ToString() & vbCrLf
                Results.Text &= "CCLastFour: " & Response.ClientDetails.CCLastFour.ToString() & vbCrLf
                Results.Text &= "SeparateInvoices: " & Response.ClientDetails.SeparateInvoices.ToString() & vbCrLf
                Results.Text &= "DisableAutoCC: " & Response.ClientDetails.DisableAutoCC.ToString() & vbCrLf
             
            End If
            
            Results.Text &= "<hr/>Test: " & Server.HtmlEncode(Response.Test.ToString()) & "<hr/>" & vbCrLf
            
        Else
            Results.Text &= "<hr/>" & "ResponseXml: Nothing<br/>" & vbCrLf
        End If
        
        ' **** Uncomment this to test the GetStats API function
        'Dim WHMCSAPI As New Secura.WHMCS.GetStats()
        'Results.Text = Server.HtmlEncode(Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", ""))
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
        ' **** Uncomment this to test the GetNameservers API function
        'Dim WHMCSAPI As New Secura.WHMCS.GetNameservers()
        'WHMCSAPI.DomainID = 1
        'Results.Text = Server.HtmlEncode(Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", ""))
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
        ' **** Uncomment this to test the AddClient API function
        'Dim WHMCSAPI As New Secura.WHMCS.AddClient()
        'WHMCSAPI.FirstName = "John"
        'WHMCSAPI.LastName = "Smith"
        'WHMCSAPI.CompanyName = "johnsmith.com"
        'WHMCSAPI.Email = "john@johnsmith.com"
        'WHMCSAPI.Address1 = "20 Oak Street"
        'WHMCSAPI.Address2 = "Smithfields"
        'WHMCSAPI.City = "London"
        'WHMCSAPI.State = ""
        'WHMCSAPI.Postcode = "W1 0QT"
        'WHMCSAPI.Country = "GB"
        'WHMCSAPI.PhoneNumber = "01234 567890"
        'WHMCSAPI.Password2 = "(testing)"
        'WHMCSAPI.Currency = "1"
        'Dim Response As Secura.WHMCS.Response = Secura.WHMCS.API.PostRequest(WHMCSAPI, APISettings, "", "")
        'Results.Text = Server.HtmlEncode(Response.Xml.ToString())
        'WHMCSObject.Text = Secura.Reflection.ObjectDebug.ReportProperties(WHMCSAPI)
        
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>WHMCS API Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <pre>
            <asp:Label ID="Results" runat="server" Text="xxxx"></asp:Label><hr />
            WHMCS Object Properties:
            <asp:Label ID="WHMCSObject" runat="server" Text="Label"></asp:Label>
        </pre>
    </div>
    </form>
</body>
</html>

